package com.blt.govdata.filters;

import javax.servlet.http.HttpSession;

import com.blt.govdata.core.constants.Constants;
import com.blt.govdata.model.TSysUser;
import com.blt.govdata.service.ITSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ContextLoader;

import com.free.oss.filter.SSOFilter;

public class CustomerSSOFilter extends SSOFilter {

    @Autowired
    ITSysUserService userService;

	public CustomerSSOFilter() {
		userService = ContextLoader.getCurrentWebApplicationContext().getBean(ITSysUserService.class);
	}
	/**
	 * 获取当前系统登录的账号
	 */
	@Override
	public String curAcc(HttpSession session) {
		TSysUser longinUser = (TSysUser)session.getAttribute(Constants.CURRENT_USER);
		return longinUser!=null?longinUser.getName():null;
	}
	/**
	 * 设置当前系统登录的账号
	 */
	@Override
	public void setAcc(HttpSession session, String account) {
        TSysUser longinUser = userService.selectById(account);
		if(longinUser != null){
	        session.setAttribute(Constants.CURRENT_USER, longinUser);
	        session.setAttribute("userId", longinUser.getId());
		}
	}
	/**
	 * 登出
	 */
	@Override
	public void logOut(HttpSession session) {
		session.removeAttribute(Constants.CURRENT_USER);
		session.removeAttribute("userId");
		session.removeAttribute("userId");
	}

}
